﻿using System;
using System.Collections.Generic;
using System.Web;

namespace dk.Helper.Base.Core
{
    public class AllyParser : IAllyParser
    {
        #region IAllyParser Members

        /// <summary>
        /// Creates the ally.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="players_in">The players_in.</param>
        /// <returns></returns>
        public IAlly CreateAlly(string data, IPlayers players_in)
        {
            try
            {
                string[] array = data.Split(',');
                int id = Convert.ToInt32(array[0]);
                string name = HttpUtility.UrlDecode(array[1]);
                string tag = HttpUtility.UrlDecode(array[2]);
                int playersCount = Convert.ToInt32(array[3]);
                int villagesCount = Convert.ToInt32(array[4]);
                int points = Convert.ToInt32(array[5]);
                int allPoints = Convert.ToInt32(array[6]);
                int rank = Convert.ToInt32(array[7]);
                IList<IPlayer> players = null;
                if (players_in.PlayersByAllyID.ContainsKey(id))
                    players = players_in.PlayersByAllyID[id];

                return new Ally(id, name, tag, playersCount, villagesCount, points, allPoints, rank, players);
            }
            catch (Exception)
            {
                return null;
            }
        }

        #endregion
    }
}